package cn.edu.sjtu.stap.cg;

import org.aspectj.org.eclipse.jdt.internal.compiler.ast.ASTNode;
import org.aspectj.org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration;

import cn.edu.sjtu.stap.hg.*;

public class CgMethod extends CgNode implements ICgShadow {
    private static final long serialVersionUID = 1L;

    public CgMethod() {
        super();
    }

    public void setASTNode(ASTNode node) {
        if (node instanceof AbstractMethodDeclaration) {
            super.setASTNode(node);
        } else {
            throw new IllegalArgumentException("Uncompatiable AST node!");
        }
    }

    // TODO Return a meaningful name.
    public String getMethodName() {
        if (null == astNode) {
            return null;
        }
        AbstractMethodDeclaration m = (AbstractMethodDeclaration)astNode;
        
        return HierarchyGraph.getFullName(m);
    }

    public String toString() {
        StringBuffer b = new StringBuffer();

        b.append("(Node Id: ");
        b.append(this.getId());
        b.append(", Method Name: ");
        b.append(this.getMethodName());
        b.append(")");

        return b.toString();
    }
}
